Skip to content

fix: clean up expected-response entry on failed handshake and preserve challenge expiry - #319

Open
MatusKysel wants to merge 1 commit into
sigp:masterfrom
MatusKysel:fix/remove-expected-response-on-failed-handshake
Open

MatusKysel wants to merge 1 commit into
sigp:masterfrom
MatusKysel:fix/remove-expected-response-on-failed-handshake

Conversation

@MatusKysel

Copy link
Copy Markdown

Follow-up to #306.

Summary

In Handler::handle_auth_message, the active challenge was removed before calling Session::establish_from_challenge, leaving two packet-filter exemption leaks:

  1. Permanent leak on handshake failure (e.g. SessionNotEstablished): when establish_from_challenge returns any error other than InvalidChallengeSignature, the challenge is already removed (so the expiry cleanup from fix: remove expected-response entry on challenge expiry #306 never runs) and fail_session only decrements filter_expected_responses for active requests, not for unsolicited challenges. The SocketAddr entry therefore remains in filter_expected_responses permanently, bypassing rate limits and bans for the lifetime of the process.
  2. Challenge expiry reset on InvalidChallengeSignature: removing and re-inserting the challenge on an invalid signature resets its HashMapDelay timer back to request_timeout, allowing repeated invalid-signature handshakes to keep the packet-filter exemption open indefinitely.

Fix

  • Borrow &Challenge from active_challenges in Session::establish_from_challenge (via an internal ChallengeError so the public Error enum stays unchanged).
  • Remove the challenge and call remove_expected_response on both success and non-signature handshake failure.
  • On InvalidSignature, leave the existing challenge in active_challenges untouched so its original expiry deadline is preserved.
  • Added unit tests covering both cases (test_failed_handshake_removes_expected_response and test_invalid_challenge_signature_does_not_reset_expiry).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant